<?php
namespace script\demo2;

class UpdateOrder
{

	/**
	 * 模拟定时处理过期的订单,将过期的订单,状态改为1,标识已过期
	 */
	public function run()
	{
		//读取config/database/shr.php的配置文件,初始化数据库,获取连接句柄
        $db = \lib\DB::instance('shr');

        //取出过期的订单
        $orderList = $db->table('order')->where('pay_status = 0')->fetchAll();
 		$now = time();
 		foreach ($orderList as $value) {

 			//将过期30s的订单状态改为1
 			if ( $now - $value['add_time'] >= 30 )
 			{
 				$db->table('order')->where("order_sn = '{$value['order_sn']}'")->update(['pay_status'=>1]);
 				echo ("处理订单: {$value['order_sn']} 处理完毕时间" . date('Y-m-d H:i:s', $now) . "\n");
 			}
 		}
 		
	}


}